<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/WEB-INF/views/include/taglib.jsp"%>
<html>
<head>
	<title>查询统计管理</title>
	<meta name="decorator" content="default"/>
	<script type="text/javascript">
		$(document).ready(function() {
			$("#add_receive").click(function(){
				var url = "${ctx }/area/areaChoose/areaQu";
				    layer.open({
				        type: 2,
				        title: '',
				        shadeClose: true,
				        shade: 0.8,
				        area: ['800px', '500px'],
				        content: url 
				      });
			});
			$(document).on("click","#btnReset",function(){
				$("#cType").val("").select2();
				$("#vaccineId").val("").select2();
				$("#beginDate").val("");
				$("#endDate").val("");
				$("#code").val("");
				$("#batchNo").val("");
				$(".receive").val("");
			});
			$.ajax({
				url : ctx + "/vaccinate/bsVaccine/findListApi",
				success : function(data) {
					vaccData = data;
					var html = "<option value=''>--请选择--</option>";
					$.each(data, function(i, t) {
						html += "<option value=" + t.id + ">" + t.name + "[" + t.pinyin
								+ "]</option>"
					});
					$("select").each(function() {
						if ($(this).hasClass("vaccineCompany")) {
							$(this).html(html);
							if (stockAndSales.vaccineId) {
								$(this).val(stockAndSales.vaccineId);
								//initCompanyName($(this).val(),companyCode);
							}
							$(this).select2();
						}
					});
				}
			});
			//initVaccName(stockAndSales.companyCode,stockAndSales.vaccineId);
			/* $(".vaccineCompany").change(function(){
				initCompanyName($(this).val());
			}); */
		});
		var stockAndSales = JSON.parse('${fns:toJson(stockAndSales)}');
		function page(n,s){
			$("#pageNo").val(n);
			$("#pageSize").val(s);
			$("#searchForm").submit();
        	return false;
        }
		function setReceive(str,code,type,id,parentIds){
			if(str)
			$(".receive").val(str);
			$("#code").val(code);
			$("#type").val(type);
			$("#id").val(id);
			$("#parentIds").val(parentIds);
		}
		
		$(document).on("click","#btnView",function(){
			debugger;
			var str = $(this).parent().parent().find("tr[data-data]").prevObject[0].dataset.data;
			var url = "${ctx }/area/vaccinate/display?str="+str;
		    layer.open({
		        type: 2,
		        title: '',
		        shadeClose: true,
		        shade: 0.8,
		        area: [screen.availWidth*0.6+'px', screen.availHeight*0.6+'px'],
		        content: url 
		     }); 
		});
		
		function down(){
			top.$.jBox.confirm("确认要导出分地区疫苗库存查询数据吗？","系统提示",function(v,h,f){
				if(v=="ok"){
					$("#searchForm").attr("action","${ctx}/area/vaccinate/export");
					$("#searchForm").submit();
				}
				$("#searchForm").attr("action","${ctx}/area/vaccinate/queryArea");
			},{buttonsFocus:1});
			top.$('.jbox-body .jbox-icon').css('top','55px');
		}
		
		/* function initVaccName(){
			var select='<option value="">--请选择--</option>';
			var url = "${ctx}/vaccinate/bsVaccine/getVaccineName";
			$.ajax({
				url : url,	
				success : function(data){
					data=$.parseJSON(data);
					var str="${bsVaccineInfo.vaccineId}";
					for(var i=0;i<data.length;i++){
						if(data[i].id==str){
							select+="<option value='"+data[i].id+"' selected>"+data[i].name+"</option>";
						}else{
						    select+="<option value='"+data[i].id+"'>"+data[i].name+"</option>";
						}
					};
					$("#vaccineId").append(select).select2();
				}
			});
		} */
		
	</script>

	<style type="text/css">
		.minWidth {
			min-width: 177px;
		}	
	</style>
	<style type="text/css">		
		#contentTable td ,#contentTable th{
			text-align: center !important;
		}
		#contentTable tbody tr td{
			font-size: 13px;
		}
	</style>
</head>
<body>
	<ul class="nav nav-tabs">
		<%-- <li class="active"><a href="${ctx}/vaccinate/bsProduct/">分地区疫苗库存查询</a></li> --%>
	    <li class="active"><a href="#">分地区疫苗库存查询</a></li>
	</ul>
	<form:form id="searchForm" modelAttribute="stockAndSales" action="${ctx}/area/vaccinate/queryArea" method="post" class="breadcrumb form-search">
		<input id="pageNo" name="pageNo" type="hidden" value="${page.pageNo}"/>
		<input id="pageSize" name="pageSize" type="hidden" value="${page.pageSize}"/>
		<input id="code" type="hidden" name="code" value="${stockAndSales.code}">
		<input id="type" type="hidden" name="type" value="${stockAndSales.type}">
		<input id="id" type="hidden" name="id" value="${stockAndSales.id}">
		<input id="parentIds" type="hidden" name="parentIds" value="${stockAndSales.parentIds}">
		<div class="breadcrumb">
			<table class="table table-bordered">

				<tr>
					<th>地区</th>
					<td>
						<form:input path="name"  htmlEscape="false" maxlength="255" readonly="true" class="span2 receive minWidth"/>
							<input id="add_receive" class="btn btn-primary btn-mini" type="button" value="选 择"/>
					</td>
					<th>疫苗属性</th>
					<td>
						<form:select path="cType" class="span2 minWidth">
							<form:option value="" label="--请选择--"/>
							<form:options items="${fns:getDictList('bs_vaccineInfo_type')}" itemLabel="label" itemValue="value" htmlEscape="false"/>
						</form:select>
					</td>
					<th>疫苗名称</th>
					<td>
						<form:select path="vaccineId" class="span2 minWidth vaccineCompany" >
						</form:select>
					</td>
				</tr>
				
				<tr>
					<th>起始日期</th>
					<td>
						<input name="beginDate" id ="beginDate" type="text" readonly="readonly" maxlength="20" class="input-medium Wdate"
							value="<fmt:formatDate value="${stockAndSales.beginDate}" pattern="yyyy-MM-dd"/>"
							onclick="WdatePicker({dateFmt:'yyyy-MM-dd',isShowClear:false});"/>
					</td>
					<th>截止日期</th>
					<td>
						<input name="endDate" id ="endDate" type="text" readonly="readonly" maxlength="20" class="input-medium Wdate"
							value="<fmt:formatDate value="${stockAndSales.endDate}" pattern="yyyy-MM-dd"/>"
							onclick="WdatePicker({dateFmt:'yyyy-MM-dd',isShowClear:false});"/>
					</td>
					<th>疫苗批号</th>
					<td>
						<form:input path="batchNo" id="batchNo" class="span2 minWidth"/>
					</td>
				</tr>
			</table>
		</div>
		<ul class="ul-form breadcrumb">
			<li class="btns"><input id="btnSubmit" class="btn btn-primary" type="submit" value="查询"/></li>
			<li class="btns"><input id="btnReset" type="button" class="btn btn-primary" value="重置"/></li>
			<li class="btns"><input onclick="down()" class="btn btn-primary" type="button" value="导出"/></li> 
			<li class="clearfix"></li>
		</ul>
	</form:form>
	
	<sys:message content="${message}"/>
	<table id="contentTable" class="table table-striped table-bordered table-condensed">
		<thead>
			<tr>
				<th>编号</th>
				<th>疫苗名称</th>
				<th>疫苗类型</th>
				<th>疫苗批号</th>
				<th>生产企业</th>
				<th>领取/购进</th>
				<th>下发/售出</th>
				<th>下级退回</th>
				<th>退回上级</th>
				<th>报废</th>
				<th>库存盘盈</th>
				<th>库存盘亏</th>
				<th>当前库存</th>
				<th>图形</th>
			</tr>
		</thead>
		<tbody>
		<c:forEach items="${page.list}" var="sas" begin="0" varStatus="status">
			<tr data-data="${sas.vaccName}_${sas.orderIn}_${sas.orderSell}_${sas.orderFromReturn}_${sas.orderReturn}_${sas.orderReject}_${sas.overage}_${sas.loss}_${sas.nowPro}">
			    <td> ${sas.no}</td>
				<td> ${sas.vaccName} </td>
				<td> ${fns:getDictLabel(sas.cType, 'bs_vaccine_type', '') }</td>
				<td>
				    ${sas.batchNo}
					<c:if test="${not empty sas.secondBatchno}">
				        <span title="(查询批号时不需要带入亚批号)" style="color: #2fa4e7;">-${sas.secondBatchno}</span>
				    </c:if>
				</td>
				<td> ${sas.companyName} </td>
				<td> ${sas.orderIn} </td>
				<td> ${sas.orderSell} </td>
				<td> ${sas.orderFromReturn} </td>
				<td> ${sas.orderReturn} </td>
				<td> ${sas.orderReject} </td>
				<td> ${sas.overage}</td>
				<td> ${sas.loss}</td>
				<td> ${sas.nowPro} </td>
				<td> 
				    <input id="btnView" type="button" class="btn btn-primary" value="图形"/>
				</td>
			</tr>
		</c:forEach>
		</tbody>
	</table>
	<div class="pagination">${page}</div>
</body>
</html>